﻿using System.Windows;
using System;
using XmlStudio.Utilities;
using Tomers.WPF.Localization;

namespace XmlStudio.Dialogs {
    /// <summary>
    /// Interaction logic for RangeDialog.xaml
    /// </summary>
    // ReSharper disable RedundantExtendsListEntry
    public partial class RangeDialog : Window {
        // ReSharper restore RedundantExtendsListEntry
        public string Range { get; private set; }

        /// <summary>
        /// Initializes a new instance if the <see cref="RangeDialog"/> class.
        /// </summary>
        public RangeDialog() {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RangeDialog"/> class.
        /// </summary>
        /// <param name="childCount">Number if child nodes of the param to expand.</param>
        public RangeDialog(int childCount)
            : this() {
            tbChildCount.Text = childCount.ToString();
        }

        protected override void OnActivated(System.EventArgs e) {
            base.OnActivated(e);
            this.tbRange.Focus();
        }

        private void Button2Click(object sender, RoutedEventArgs e) {
            this.Range = tbRange.Text;
            try {
                this.Range.ParseRange();
            } catch(ArgumentException) {
                MessageBox.Show(LanguageDictionary.GetDictionary(LanguageContext.Instance.Culture).Translate<string>("RangeDialog.IncorrectRange", "Text"),
                    LanguageDictionary.GetDictionary(LanguageContext.Instance.Culture).Translate<string>("RangeDialog.Warning", "Text"),
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                return;
            }

            this.DialogResult = true;
            this.Close();
        }
    }
}
